package com.net.xpay.common.manager.impl;

import com.google.common.base.Preconditions;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.dao.UserBusinessAuthMapper;
import com.net.xpay.common.domain.UserBusinessAuth;
import com.net.xpay.common.manager.UserBusinessAuthManager;
import com.net.xpay.core.model.AdminUserBusinesAuthSearchModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class UserBusinessAuthManagerImpl extends AbstractManager<UserBusinessAuth> implements UserBusinessAuthManager{

    @Autowired
    private UserBusinessAuthMapper mapper;


    @Override
    protected BasicMapper<Long, UserBusinessAuth> getMapper() {
        return mapper;
    }

    @Override
    public UserBusinessAuth getByUserId(Long userId) {
        Preconditions.checkArgument(userId != null );
        UserBusinessAuth condition = new UserBusinessAuth();
        condition.setUserId(userId);
        return getByCondition(condition);
    }

    @Override
    public UserBusinessAuth findById(Long userId, Long id) {
        Preconditions.checkArgument(userId != null && id != null);
        UserBusinessAuth condition = new UserBusinessAuth();
        condition.setUserId(userId);
        condition.setId(id);
        return getByCondition(condition);
    }

    @Override
    public List<UserBusinessAuth> search(AdminUserBusinesAuthSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        return nonEmptyList(mapper.search(searchModel, page));
    }


    @Override
    public long searchCount(AdminUserBusinesAuthSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchCount(searchModel);
    }

    @Override
    public List<UserBusinessAuth> list(AdminUserBusinesAuthSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return nonEmptyList(mapper.list(searchModel));
    }
}
